package echat.future.cn.echat.my.view;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMMessage;

import java.util.ArrayList;
import java.util.List;

import echat.future.cn.echat.R;
import echat.future.cn.echat.databinding.ActivitySendGroupMessageBinding;
import echat.future.cn.echat.my.api.UserApi;
import echat.future.cn.echat.my.bean.FansBean;
import echat.future.cn.echat.my.utils.HttpUtilsRequst;
import echat.future.cn.echat.my.utils.UserHelper;
import echat.future.cn.echat.my.weight.Navagation.AdapterNavagation;
import echat.future.cn.echat.my.weight.Navagation.IBaseNavagation;

/**
 * 群发短信
 */
public class SendGroupMessageActivity extends BaseActivity<ActivitySendGroupMessageBinding>{

    @Override
    public int layoutId() {
        return R.layout.activity_send_group_message;
    }

    @Override
    public IBaseNavagation navagation() {
        return new AdapterNavagation(this).setTitle("给粉丝群发私信", 16, R.color.white).setBack(R.drawable.btn_back).setNavagationBackgroudColor(R.color.color_161823);

    }
    List<FansBean> mDatas = new ArrayList<>();
    @Override
    public void initView() {

        new HttpUtilsRequst<List<FansBean>>(this,HttpUtilsRequst.retrofitClient.create(UserApi.class).getMyFans(UserHelper.getToken()))
                .setmOnRequstSuccessListener((HttpUtilsRequst.OnRequstSuccessListener<List<FansBean>>) o -> {
                    mDatas.clear();
                    mDatas.addAll(o);
                })
                .start();

        findViewById(R.id.textView20).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String content = ((TextView)findViewById(R.id.world)).getText().toString();
                if(mDatas.size()<0){
                    Toast.makeText(SendGroupMessageActivity.this,"您还没有粉丝",Toast.LENGTH_SHORT).show();
                    return;
                }
                if(TextUtils.isEmpty(content)){
                    Toast.makeText(SendGroupMessageActivity.this,"请输入您想说的话",Toast.LENGTH_SHORT).show();
                    return;
                }
                for(FansBean fb:mDatas){
                    EMMessage message = EMMessage.createTxtSendMessage(content, fb.getMobile());
                    EMClient.getInstance().chatManager().sendMessage(message);
                }
                Toast.makeText(SendGroupMessageActivity.this,"群发成功",Toast.LENGTH_SHORT).show();
                finish();
            }
        });

    }
}
